package com.flower.service.impl;

import com.flower.mapper.UserMapper;
import com.flower.model.dto.LoginDto;
import com.flower.model.entity.Login;
import com.flower.model.entity.SysMenu;
import com.flower.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName UserServiceImpl
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/10 16:19
 *@Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public Login login(LoginDto loginDto) {
        Login login = userMapper.login(loginDto);
        return login;
    }

    @Override
    public List<SysMenu> getMenus() {
        List<SysMenu> menus = userMapper.getAllMenu();
        List<SysMenu> flmenus = new ArrayList<>();
        for (SysMenu menu : menus) {
            if (menu.getPid() == null) {
                flmenus.add(menu);
            }

        }
        for (SysMenu menu : flmenus) {
            List<SysMenu> children = new ArrayList<>();
            for (SysMenu menu1 : menus) {
                if (menu.getId().equals(menu1.getPid())) {
                    children.add(menu1);
                }
            }
            menu.setChildren(children);
        }

        return flmenus;
    }
}
